package event;

import java.util.Hashtable;
import java.util.LinkedList;

import property.Property;
import database.RecordSearch;
import dbmanager.Column;
import dbmanager.DBManager;
import dbmanager.GetIdName;

public class Reflectparent implements Event 
{
	String msg;
	DBManager database;
	GetIdName gid;
	String object;
	String Request="request";
	String id;
	String Refelect="reflect";
	
	public void SetData(String msg, String transaction_type, String tid,String userid) 
	{
		this.msg = msg;
		this.id = tid;
	}

	public boolean getResult() 
	{
		Hashtable<Object, Object> table = new Hashtable<Object, Object>();
		table.put("mid", object);
		table.put("pid", Request);
		table.put("td", "null");
		RecordSearch rs =new RecordSearch(database);
		rs.setConditionMap(table);
		String line[] = rs.getArrayFromResultSet();
		for(int i=0;i<line.length;i++)
		{
			String splitline[] = line[i].split("\t");
			String value = splitline[Column.pv_index-1];
			if(value.equals("0"))
				Request = splitline[Column.vt_index-1];
			else
				Request = gid.getItem(value);
		}		
	//	if(msg.equalsIgnoreCase(Request))
		{	
			table.put("pid",Refelect);
			rs.setConditionMap(table);
			line = rs.getArrayFromResultSet();
			if(line.length>0)
			{
				Hashtable<Object, Object> query = new Hashtable<Object, Object>();
				utility.findParentObject parenobject = new utility.findParentObject();
				parenobject.setDatabaseObject(database);
				for(int i=0;i<line.length;i++)
				{
					String splitline[] = line[i].split("\t");
					LinkedList<Object> reportlist= parenobject.findParentObject(id, splitline[Column.pv_index-1]);
					for(int j=0;j<reportlist.size();j++)
					{
						Property property =new Property(database);
						property.setMid(reportlist.get(i).toString());
						property.setPid(splitline[Column.pv_index-1]);
						String reporton= property.getValue();
						String reportname = gid.getItem(reportlist.get(i).toString());
						query.put("report_name", reportname);
						query.put("status","0");
						query.put("process", "mod");
						query.put("reportOn",reporton);
						database.getInsert("report_master", query);
					}
				}
			}	
		}	
		return true;
	}

	public void initializationData(DBManager database) 
	{
		this.database = database;
		gid =new GetIdName(database);
		Request =gid.getId(Request);  
		Refelect = gid.getId(Refelect);
	}

	public void setObject(String Object) 
	{
		this.object = Object;
	}
	
	public void SetData(String Product, String type, String masterid,
			String userid, String Process) 
	{
		this.msg = msg;
		this.id = masterid;
	}
	
	public static void main(String[] args) 
	{
		Reflectparent rp =new Reflectparent();		
		rp.SetData("property_details", "","7289" , "", "");
		rp.setObject("10813");
		DBManager database =new DBManager();
		database.getConnect();
		rp.initializationData(database);
		rp.getResult();
	}


	public boolean afterAdd() 
	{
		return getResult();
	}

	
	public boolean afterDel() 
	{
		return getResult();
	}

	
	public boolean afterMod() 
	{
		return getResult();
	}

	
	public boolean afterView() 
	{
		return getResult();
	}

}
